package javaCode.chapter12.homework01;

/**
 * @author 徐州城
 * @version 1.0
 */
public class Homework05 {
    public static void main(String[] args) {
        String s1 = "xzcedu";
        Animal a = new Animal(s1);
        Animal b = new Animal(s1);
        System.out.println(a == b); //f ==判断的是对象的地址
        System.out.println(a.equals(b)); //f 对象比较的地址 没有重写Object类的equals() 所以错误
        System.out.println(a.name == b.name); //t 它们的name都指向了同一个 常量池的xzcedu

        String s4 = new String("xzcedu");
        String s5 = "xzcedu";

        System.out.println(s1 == s4); //f
        System.out.println(s1 == s5); //t

        String t1 = "hello" + s1;
        String t2 = "helloxzcedu";
        System.out.println(t1.intern() == t2); //t
    }
}

class Animal {
    String name;

    public Animal(String name) {
        this.name = name;
    }
}